local qiewei = fk.CreateSkill{
  name = "lingling__qiewei",
  tags = { "DIY.Switch" },
  dynamic_desc = function (self, player, lang)
    return "lingling__qiewei"..player:getMark(self.name)
  end,
}

Fk:loadTranslationTable{
  ["lingling__qiewei"] = "窃威",
  [":lingling__qiewei"] = "转换技，出牌阶段，你可以将一张牌当①【推心置腹】②【调虎离山】③【顺手牵羊】使用。若为【顺手牵羊】，"..
  "结算结束后你可以视为对目标角色使用【杀】。",

  [":lingling__qiewei0"] = "转换技，出牌阶段，你可以将一张牌当<font color=\"#E0DB2F\">①【推心置腹】</font>②【调虎离山】③【顺手牵羊】使用。"..
  "若为【顺手牵羊】，结算结束后你可以视为对目标角色使用【杀】。",
  [":lingling__qiewei1"] = "转换技，出牌阶段，你可以将一张牌当①【推心置腹】<font color=\"#E0DB2F\">②【调虎离山】</font>③【顺手牵羊】使用。"..
  "若为【顺手牵羊】，结算结束后你可以视为对目标角色使用【杀】。",
  [":lingling__qiewei2"] = "转换技，出牌阶段，你可以将一张牌当①【推心置腹】②【调虎离山】<font color=\"#E0DB2F\">③【顺手牵羊】</font>使用。"..
  "若为【顺手牵羊】，结算结束后你可以视为对目标角色使用【杀】。",

  ["#lingling__qiewei0"] = "窃威：你可以将一张牌当【推心置腹】使用",
  ["#lingling__qiewei1"] = "窃威：你可以将一张牌当【调虎离山】使用",
  ["#lingling__qiewei2"] = "窃威：你可以将一张牌当【顺手牵羊】使用",
  ["#lingling__qiewei-slash"] = "窃威：是否视为对目标角色使用【杀】？",
}

qiewei:addEffect("viewas", {
  anim_type = "switch",
  mute_card = false,
  prompt = function(self, player)
    return "#lingling__qiewei"..player:getMark(qiewei.name)
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card
    if player:getMark(qiewei.name) == 0 then
      card = Fk:cloneCard("ling__sincere_treat")
    elseif player:getMark(qiewei.name) == 1 then
      card = Fk:cloneCard("ling__lure_tiger")
    elseif player:getMark(qiewei.name) == 2 then
      card = Fk:cloneCard("ling__snatch")
    end
    card.skillName = qiewei.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    room:addPlayerMark(player, qiewei.name, 1)
    if player:getMark(qiewei.name) > 2 then
      room:setPlayerMark(player, qiewei.name, 0)
    end
  end,
  after_use = function (self, player, use)
    if use.card.trueName == "snatch" and not player.dead then
      local room = player.room
      local targets = table.filter(use.tos, function (p)
        return player:canUseTo(Fk:cloneCard("slash"), p, { bypass_distances = true, bypass_times = true })
      end)
      if #targets > 0 and
        room:askToSkillInvoke(player, {
          skill_name = qiewei.name,
          prompt = "#lingling__qiewei-slash",
        }) then
        room:useVirtualCard("slash", nil, player, targets, qiewei.name, true)
      end
    end
  end,
})

qiewei:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, qiewei.name, player:usedSkillTimes(qiewei.name, Player.HistoryGame) % 3)
end)

qiewei:addAI(nil, "vs_skill")

return qiewei
